<?php
require_once '../sub/init.php';
header("Cache-control: private");
require_once 'chkUadm.php';
require_once ZEAI.'cache/config_up.php';
require_once ZEAI.'cache/config_sms.php';
require_once ZEAI.'sub/zeai_up_func.php';
require_once ZEAI.'api/zeai_RZ.php';
switch ($submitok) {
	case"cert_update":
		if(!in_array('cert_auto',$QXARR))exit(noauth());
		if(empty($truename) || str_len($truename)<4 || !ifsfz($identitynum))json_exit(array('flag'=>0,'msg'=>'【姓名】或【身份证号】不正确'));
		if($t=='identity'){
			if( !ifmob($mob))json_exit(array('flag'=>0,'msg'=>'【手机号码】不正确'));
			$retarr = Zeai_RZ_mob3($truename,$identitynum,$mob);
		}elseif($t=='photo'){
			if(@file_exists(ZEAI.'up'.DIRECTORY_SEPARATOR.$photo_b)){
				$retarr = Zeai_RZ_face_id_card($truename,$identitynum,ZEAI.'up'.DIRECTORY_SEPARATOR.$photo_b);
			}else{
				json_exit(array('flag'=>0,'msg'=>'请检查照片格式是否为jpg/png/gif格式'));
			}
		}
		if($retarr['flag']==1){
			if(ifint($uid)){
				$row = $db->ROW(__TBL_USER__,"nickname,RZ","id=".$uid,"name");
				$nickname = trimhtml(dataIO($row['nickname'],'out'));
				$RZ = $row['RZ'];
				if(empty($RZ)){
					$RZ=$t;
				}else{
					$RZarr=explode(',',$RZ);
					if(!in_array($t,$RZarr)){
						$RZarr[]=$t;
						$RZ = implode(",",$RZarr);
					}
				}
				$db->query("UPDATE ".__TBL_USER__." SET RZ='$RZ' WHERE id=".$uid);
				AddLog('【在线'.RZtitle($t).'核验】->用户【'.$nickname.'（uid:'.$uid.'）】->点亮');
			}
			json_exit(array('flag'=>1,'msg'=>'<font class=\"S18 \">验证结果：</font><font class=\"S18 C090 \"><i class=\"ico\">&#xe67f;</i> 同一个人</font>'));
			
		}else{
			json_exit(array('flag'=>0,'msg'=>'<font class=\"S18 \">验证结果：</font>：<font class=\"S18 C999 \"><i class=\"ico\">&#xe65b;</i> '.$retarr['msg'].'</font>'));
		}
	break;
	case"ajax_photo_b_up":
		if(!in_array('cert_auto',$QXARR))exit(noauth());
		if (ifpostpic($file['tmp_name'])){
			$dbname = setphotodbname('tmp',$file['tmp_name'],$session_uid.'photo_');
			if (!up_send($file,$dbname,0,$_UP['upBsize']))json_exit(array('flag'=>0,'msg'=>'图片写入失败'));
			AddLog('【在线真人比对】上传图片->url:'.$dbname);
			json_exit(array('flag'=>1,'msg'=>'上传成功','dbname'=>$dbname));
		}else{
			json_exit(array('flag'=>0,'msg'=>'zeai_tmp_name_error'));
		}
	break;
	case"ajax_tmp_del":
		$url = str_replace(UP,"",$pathurl);
		if(!empty($url))@up_send_admindel($url.'|'.smb($url,'m').'|'.smb($url,'b'),$delvar);exit;
	break;
}
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script src="<?php echo RES;?>www_zeai_cn.js?<?php echo $_ZEAI['cache_str'];?>"></script>
<script>var up2='<?php echo UP;?>',upMaxMB=<?php echo $_UP['upMaxMB']; ?>;</script>
<script src="js/up.js?<?php echo $_ZEAI['cache_str'];?>"></script>
<link href="css/main.css?<?php echo $_ZEAI['cache_str'];?>" rel="stylesheet" type="text/css">
</head>
<style>
.table .tbodyT{font-size:18px;height:60px}
.table .tbodyT h6{color:#999;display:block}
</style>
<body>
<div class="box">
	<div class="boxL">
        <a href="cert.php">用户认证列表<?php echo '<b>'.$db->COUNT(__TBL_RZ__).'</b>';?></a>
        <a href="cert.php?f=f0">用户未审失败<?php echo '<b>'.$db->COUNT(__TBL_RZ__,"flag=0").'</b>';?></a>
        <div class="br W80_"></div>
        <a href="cert_auto.php?t=identity"<?php echo ($t == 'identity')?' class="ed"':'';?>>在线实名核验</a>
        <a href="cert_auto.php?t=photo"<?php echo ($t == 'photo')?' class="ed"':'';?>>在线真人比对</a>
	</div>
	<div class="boxR">
    	<?php if(!in_array('cert_auto',$QXARR))exit(noauth());?>
        <form name="ZEAI_FORM" method="POST" action="<?php echo SELF;?>">
        <table class="table Mtop30 W700">
        <tr><td colspan="2" class="tbodyT">
        <?php if ($t=='identity'){?>
            <center>在线实名核验<h6><font class="Cf00">*</font>号为必填，会根据“手机号+姓名+身份证号”自动进入“电信/移动/联通”数据库验证是否是同一个人</h6></center>
        <?php }elseif($t=='photo'){ ?>
            <center>在线真人比对<h6><font class="Cf00">*</font>号为必填，会根据“人脸照片+姓名+身份证号”和公安库里面照片进行比对验证是否是同一个人</h6></center>
        <?php }?>
        </td></tr>
        
        <tr>
        <td class="tdL">用户UID</td>
        <td class="tdR"><input name="uid" id="uid" type="text" class="input size2 W100" size="40" maxlength="8" autocomplete="off" /><span class="tips">如果填入用户ID，将直接点亮认证标图</span></td>
        </tr>
        
        <?php if ($t=='identity'){?>
        <tr>
        <td class="tdL"><font class="Cf00">*</font> 手机号码</td>
        <td class="tdR"><input name="mob" id="mob" type="text" class="input size2 W300" size="40" maxlength="11" autocomplete="off" /></td>
        </tr>
        <?php }elseif($t=='photo'){ ?>
        <tr>
        <td class="tdL"><font class="Cf00">*</font> 人脸照片</td>
        <td class="tdR">
            <div class="picli60" id="photo_b_box">
              <li class="add" id="photo_b_btn"></li>
            </div>
            <input name="photo_b" id="photo_b" type="hidden" value="" />
            <script>adm_path_up({boxid:o(photo_b_box),btnid:o(photo_b_btn),inputid:o(photo_b),url:'cert_auto.php',submitok_add:'ajax_photo_b_up'});</script>
        </td>
        </tr>
        <?php }?>
        <tr>
        <td class="tdL"><font class="Cf00">*</font> 真实姓名</td>
        <td class="tdR"><input name="truename" id="truename" type="text" class="input size2 W300" size="40" maxlength="15" autocomplete="off" /></td>
        </tr>
        <tr>
        <td class="tdL"><font class="Cf00">*</font> 身份证号</td>
        <td class="tdR"><input name="identitynum" type="text" id="identitynum" value="" class="input size2 W300" maxlength="18"></td>
        </tr>
        <tr>
        <td colspan="2" align="center">
        <input class="btn size3" type="button" id="btn" value="提交认证" />
        <input name="submitok" type="hidden" value="cert_update" />
        <input name="t" type="hidden" value="<?php echo $t;?>" />
        </td>
        </tr>
        </table>
        </form>
	</div>
    <div class="clear"></div>
</div>
<script>
btn.onclick=function(){
	<?php if ($t=='identity'){?>
		if(!zeai.ifmob(mob.value)){zeai.msg('请输入【手机号码】',mob);return false;}
		var str='通信运营商实名库';
	<?php }elseif($t=='photo'){ ?>
		if(zeai.empty(photo_b.value)){zeai.msg('请上传【人脸照片】');return false;}
		var str='公安库';
	<?php }?>
	if(zeai.empty(truename.value)){zeai.msg('请输入【真实姓名】',truename);return false;}
	if(zeai.empty(identitynum.value)){zeai.msg('请输入【身份证号】',identitynum);return false;}
	zeai.confirm('确定提交么？<br>1.需要正确设置接口参数才能生效　<i class="ico">&#xe62d;</i> <a href="var.php?t=rz" class="Clan">配置接口</a><br>2.验证接口是收费的，一般3毛左右一次',function(){
		zeai.msg('正在连接'+str+'验证...',{time:30});
		zeai.ajax({url:'cert_auto'+zeai.extname,form:ZEAI_FORM},function(e){var rs=zeai.jsoneval(e);
			zeai.msg(0);zeai.alert(rs.msg);
		});
	});
}
</script>
<?php require_once 'bottomadm.php';?>